package utils;

public class ThreadLock
{
    private boolean lock = false;

    public synchronized void lock()
    {
        Logger.logInfo(Thread.currentThread() + " try lock");
        if (lock)
        {
            try
            {
                Logger.logInfo(Thread.currentThread() + " wait");
                wait();
            }
            catch (InterruptedException e)
            {
                Logger.logException(e);
            }
        }
        Logger.logInfo(Thread.currentThread() + " lock");
        lock = true;
    }

    public synchronized void unlock()
    {
        Logger.logInfo(Thread.currentThread() + " release");
        lock = false;
        notifyAll();
    }
}
